﻿using System;
using Autofac;
using System.Linq;
using System.Web.Mvc;
using System.Collections;
using System.Collections.Generic;

namespace GBlog.Core.Infrastructure
{
    public class Dependency : IDependencyResolver
    {
        private readonly IContainer container;

        public Dependency(IContainer container)
        {
            this.container = container;
        }

        public object GetService(Type type)
        {
            return container.IsRegistered(type) ? container.Resolve(type) : null;
        }

        public IEnumerable<object> GetServices(Type type)
        {
            Type enumerableServiceType = typeof(IEnumerable<>).MakeGenericType(type);
            object instance = container.Resolve(enumerableServiceType);
            return ((IEnumerable)instance).Cast<object>();
        }
    }
}